import java.util.Stack;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution227 {

    public static void main(String args[]) {
        Solution227 s = new Solution227();
        System.out.println(s.calculate("0 - 1"));
    }

    public int calculate(String s) {
        Stack<Integer> vs = new Stack<>();
        Stack<Character> ops = new Stack<>();

        int v = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (isSpace(s.charAt(i))) {
                continue;
            }
            if (!isOp(c)) {
                v = v * 10 + (c - '0');
            } else {
                //先判断栈顶是否high
                if (!ops.isEmpty() && isHighOp(ops.peek())) {
                    int ret = cal(vs.pop(), v, ops.pop());
                    vs.push(ret);
                } else {
                    vs.push(v);
                }

                v = 0;
                ops.push(c);
            }
        }
        if (!ops.isEmpty() && isHighOp(ops.peek())) {
            int ret = cal(vs.pop(), v, ops.pop());
            vs.push(ret);
        } else {
            vs.push(v);
        }

        Stack<Integer> nvs = new Stack<>();
        while (!vs.isEmpty()) {
            nvs.push(vs.pop());
        }
        Stack<Character> nops = new Stack<>();
        while (!ops.isEmpty()) {
            nops.push(ops.pop());
        }

        while (nvs.size() > 1) {
            int a = nvs.pop();
            int b = nvs.pop();
            int ret = cal(a, b, nops.pop());
            nvs.push(ret);
        }
        return nvs.pop();
    }

    public int cal(int a, int b, char op) {
        if (op == '+') {
            return a + b;
        }
        if (op == '-') {
            return a - b;
        }
        if (op == '*') {
            return a * b;
        }
        if (op == '/') {
            return a / b;
        }
        return 0;
    }

    public boolean isSpace(char c) {
        if (Character.isWhitespace(c)) {
            return true;
        }
        return false;
    }

    public boolean isOp(char c) {
        if (c == '+' || c == '-' || c == '*' || c == '/') {
            return true;
        }
        return false;
    }

    public boolean isHighOp(char c) {
        if (c == '*' || c == '/') {
            return true;
        }
        return false;
    }

}
